﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
using HomeStayWebCP.Models.BusinessObject;

namespace HomeStayWebCP.Models
{
    public class ManagePostsModel
    {
        readonly PostsDataModel _dataModel = new PostsDataModel();
        ManagePostsDataModel managePostsDataModeldataModel = new ManagePostsDataModel();
        public IList<Post_ManagePosts_View> GetListPost(int status)
        {
            ManagePostsDataModel dataModel = new ManagePostsDataModel();
            List<Post_ManagePosts_View> listPost = dataModel.GetListPosts(status);
            return listPost;
        }

        #region Khoana - ManagePosts GetDetailOfPost
        public PostItem ManGetDetailOfPost(int postId)
        {
            PostsDataModel datamodel = new PostsDataModel();
            List<Store_ManagePosts_GetDetailOfPost_Result> detailPost = datamodel.ManagePostsGetDetailOfPost(postId);
            if (detailPost.Count > 0)
            {
                Store_ManagePosts_GetDetailOfPost_Result temp = detailPost[0];
                PostItem pitem = new PostItem
                {
                    PostID = postId,
                    Title = temp.Title,
                    ContactName = temp.ContactName,
                    Content = temp.Content,
                    MobilePhone = temp.MobilePhone,
                    TelePhone = temp.TelePhone,
                    Email = temp.ContactEmail,
                    TimeCreated = temp.TimeCreated,
                    Area = temp.Area,
                    AddressDetail = temp.AddressDetail,
                    Province = temp.Province,
                    District = temp.District,
                    HasGara = temp.HasGara,
                    HasGarden = temp.HasGarden,
                    HasKitchen = temp.HasKitchen,
                    NumBadroom = temp.NumBadroom,
                    NumOfWC = temp.NumOfWC,
                    NumSittingRoom = temp.NumSittingRoom,
                    Ordinate = temp.Ordinate,
                    PricePerDay = temp.PricePerDay,
                    PricePerMonth =temp.PricePerMonth,
                    PricePerWeek = temp.PricePerWeek,
                    Storey = temp.Storey,
                    TypeOfHouse = temp.TypeOfHouse,
                    PostAvailable = temp.IsAvailable,
                    Status = temp.PostStatus,
                    UserReview = temp.UserReview,
                    ReviewedTime = temp.ReviewDate
                };
                return pitem;
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region Khoana - ManagePost AcceptPost
        public int AcceptPost (int postId, string reviewBy)
        {
            return _dataModel.AcceptPost(postId, reviewBy);
        }
        #endregion

        #region Khoana - ManagePost RejectPost
        public int RejectPost(int postId, string reviewBy)
        {
            return _dataModel.RejectPost(postId, reviewBy);
        }
        #endregion

        #region Khoana - Get time rejected post
        public int GetTimeRejectedPost (int postId)
        {
            int timeRejected = managePostsDataModeldataModel.GetTimeRejectedPost(postId);
            return timeRejected;
        }
        #endregion

        #region Khoana - Delete a Post
        public void DeletePost(int postId)
        {
            managePostsDataModeldataModel.DeletePost(postId);
        }
        #endregion
    }
}